package cmarter.dev.entities;

import java.util.ArrayList;
import java.util.List;

public class Apple {
	

	private String color;
	private Double weight;
	private String name;

	public Apple(String color, Double weight, String name) {
		super();
		this.color = color;
		this.weight = weight;
		this.name = name;
	}

	public Apple() {
		super();
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static boolean isGreen(Apple a) {
		return "green".equalsIgnoreCase(a.getColor());
	}

	public static boolean isHeavy(Apple a) {
		return a.getWeight() >= 150d;
	}

	public static interface Predicate<T> {
		public boolean test(T t);
	}

	public static List<Apple> filterApples(List<Apple> apples, Predicate<Apple> p) {
		List<Apple> result = new ArrayList<>();
		for (Apple a : apples) {
			if (p.test(a)) {
				result.add(a);
			}
		}
		return result;
	}
	
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("[ name: " + this.name + ", ");
		sb.append("weight: " + this.weight + ", ");
		sb.append("color: " + this.color + " ]");
		return sb.toString();
	}

}
